<?php
class AppController
{
    var $db;
    function AppController($db){
        global $config;
        $this->db = $db;
    }

    function group_message($details){
        if (preg_match('/([\d\w-_]+) (.+)/i',$details['message'], $m)) {
            $members = $this->db->group_members($m[1]);
            if (count($members) < 1) {
                $msg = str_replace('::group::',$m[1], $this->db->get_tmpl('group_does_not_exist'));
                $this->db->send_sms($details['msisdn'], $msg ,$details['smsc'] ); die();
                exit();
            }
            foreach ($members as $member){
                $this->db->send_sms($member['msisdn'], $m[2], $details['smsc']);
            }
            $msg = str_replace('::group::',$m[1], $this->db->get_tmpl('group_send_ok'));
            $this->db->send_sms($details['msisdn'], $msg ,$details['smsc'] ); die();
            exit();

        }
    }

    function balance($details){
        $this->db->send_sms($details['msisdn'],$this->db->get_tmpl('balance2'),$details['smsc'] ); die();
	return;
        if (preg_match('/(\d+)/', $details['message'], $m)) {
            $student_no = $m[1];
        } else {
            exit();
        }

        $enrollment_id = $this->db->enrollment_id_from_studno($student_no);
        if (!$enrollment_id) {
            $this->db->send_sms($details['msisdn'], $this->db->get_tmpl('stud_does_not_exist'), $details['smsc']);
            exit();
        }
        $balance = number_format($this->db->get_outstanding($enrollment_id),2);
        $this->db->send_sms($details['msisdn'], str_replace('::balance::', $balance, $this->db->get_tmpl('balance')),$details['smsc'] ); die();
    }

}
?>
